Problem #1

DPLYR aggregation.

library("readxl")
library("dplyr")
my_data <- read_excel("dow_jones_index.xlsx")
my_data2<-my_data %>%
  group_by(stock) %>% 
  mutate(Weekly_pct_change = (open-lag(open))/lag(open) * 100)  %>% 
  summarise(meanWeekly_pct_change = mean(Weekly_pct_change,na.rm=TRUE), .groups = 'drop') %>% 
  arrange(desc(meanWeekly_pct_change))
  
  
my_data2 %>% print(n = Inf) 
## # A tibble: 30 x 2
##    stock meanWeekly_pct_change
##    <chr>                 <dbl>
##  1 PFE                 0.560  
##  2 BA                  0.500  
##  3 AXP                 0.494  
##  4 IBM                 0.457  
##  5 CVX                 0.357  
##  6 KRFT                0.348  
##  7 XOM                 0.310  
##  8 UTX                 0.289  
##  9 MCD                 0.288  
## 10 JNJ                 0.244  
## 11 MMM                 0.239  
## 12 T                   0.157  
## 13 CAT                 0.155  
## 14 TRV                 0.133  
## 15 INTC                0.0855 
## 16 DIS                 0.0549 
## 17 PG                  0.0191 
## 18 GE                  0.00181
## 19 DD                 -0.0118 
## 20 KO                 -0.0174 
## 21 VZ                 -0.0651 
## 22 MRK                -0.0754 
## 23 HD                 -0.0763 
## 24 WMT                -0.107  
## 25 JPM                -0.218  
## 26 AA                 -0.232  
## 27 MSFT               -0.598  
## 28 HPQ                -0.720  
## 29 BAC                -1.05   
## 30 CSCO               -1.22

Problems #2 and #4 Combined

A random forest is used to generate feature importance. I’m transforming all data into factors. This is a quick and efficient approach and suitable given the small size of the data. The output at the end highlights the differences between the excel and database files.

##Step1 - read in the packages

  library(readxl)
  library(dplyr)
  library(magrittr)
  library(vip)
  library(recipes)
  library(workflows)
  library(caret)
  library(DBI)
  library(RSQLite)
  garfield<-read_excel("garfield_activity.xlsx")
  garfield
## # A tibble: 21 x 13
##    `8AM` `9AM` `10AM` `11AM` Noon  `1PM` `2PM` `3PM` `4PM` `5PM` Commute
##    <chr> <dbl>  <dbl>  <dbl> <chr> <dbl> <dbl> <dbl> <chr> <dbl> <chr>  
##  1 Coff…     5      0      8 Sand…     6     9     2 Tea       2 Long   
##  2 Doug…     0      6      2 Lent…    10     0     1 Ping…     7 Short  
##  3 Coff…     3      7     10 Taco      8     4     6 Ping…     2 Short  
##  4 Coff…     1      7      3 Sand…     7     7     8 Ping…     3 Short  
##  5 Doug…     5      0      2 Sand…     5     6     9 Tea       3 Long   
##  6 Sand…     8      8      8 Lent…     3    10    10 Coff…     0 Short  
##  7 Doug…     7      8      1 Lent…     6     6     4 Coff…     9 Short  
##  8 Coff…     7      7      2 Taco     10     7    10 Tea       8 Short  
##  9 Sand…     2      2      8 Lent…     8     8     0 Ping…    10 Short  
## 10 Coff…     6      9      1 Taco      8     8     4 Work…     4 Short  
## # … with 11 more rows, and 2 more variables: DayOfWeek <chr>, WatchTV <chr>
  garfield2<-garfield %<>%
    mutate_if(is.character,as.factor)%<>%
    mutate_if(is.numeric,as.factor)
  
  garfield4<-garfield2[!(is.na(garfield2$WatchTV)),]

  #garfieldglm<-glm(WatchTV ~ ., data=garfield4, family=binomial)
  
  #train the random forest
    rf_fit <- train(WatchTV ~ ., 
                  data = garfield4, 
                  method = "ranger",
                  #tuneGrid = tgrid,
                  importance = "permutation")
    
    rf_fit
## Random Forest 
## 
## 19 samples
## 12 predictors
##  2 classes: 'No', 'Yes' 
## 
## No pre-processing
## Resampling: Bootstrapped (25 reps) 
## Summary of sample sizes: 19, 19, 19, 19, 19, 19, ... 
## Resampling results across tuning parameters:
## 
##   mtry  splitrule   Accuracy   Kappa     
##    2    gini        0.4642540  0.08410407
##    2    extratrees  0.4647460  0.08380300
##   40    gini        0.6534444  0.29289742
##   40    extratrees  0.6487778  0.27356408
##   78    gini        0.6562222  0.28512172
##   78    extratrees  0.6676508  0.30642607
## 
## Tuning parameter 'min.node.size' was held constant at a value of 1
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were mtry = 78, splitrule = extratrees
##  and min.node.size = 1.
    #generate variable importances
    #the top two indicators are sandwich at noon and a short commute  
    varImp(rf_fit, scale = TRUE)
## ranger variable importance
## 
##   only 20 most important variables shown (out of 78)
## 
##              Overall
## NoonSandwich 100.000
## CommuteShort  11.178
## `11AM`3        6.193
## `3PM`3         5.401
## `11AM`7        4.932
## `3PM`2         4.872
## `3PM`10        4.781
## `9AM`7         4.427
## `2PM`8         4.124
## `9AM`4         4.102
## `11AM`4        4.102
## `5PM`5         4.102
## `5PM`9         4.102
## `1PM`4         4.102
## `1PM`5         4.102
## `1PM`1         4.102
## `1PM`2         4.102
## `4PM`Tea       4.102
## `3PM`1         4.102
## `9AM`5         4.102
  #problem 4
    
    #read in the data base
  con<-dbConnect(SQLite(), 'test.db')
  
  dbListTables(con)
## [1] "garfield"       "garfield_stats"
  #read in the garfield table
  garfielddb_table<-dbReadTable(con, "garfield")
  
  ##compare to garfield excel sheet
  
  dim(garfielddb_table)
## [1] 21 15
  dim(garfield)
## [1] 21 13
  colnames(garfielddb_table)
##  [1] "index"     "X8AM"      "X9AM"      "X10AM"     "X11AM"     "Noon"     
##  [7] "X1PM"      "X2PM"      "X3PM"      "X4PM"      "X5PM"      "Commute"  
## [13] "DayOfWeek" "WatchTV"   "New.Field"
  colnames(garfielddb_table)
##  [1] "index"     "X8AM"      "X9AM"      "X10AM"     "X11AM"     "Noon"     
##  [7] "X1PM"      "X2PM"      "X3PM"      "X4PM"      "X5PM"      "Commute"  
## [13] "DayOfWeek" "WatchTV"   "New.Field"
  #highlight columns that are the same
  
  colnames(garfielddb_table)[colnames(garfielddb_table) %in% colnames(garfield)]
## [1] "Noon"      "Commute"   "DayOfWeek" "WatchTV"
  #highlight columns that are different
    #There are Xs in front of the times in the database table.  To reconcile the two tables, the index and New.Field columns should be removed from the database table. 
  colnames(garfielddb_table)[!(colnames(garfielddb_table) %in% colnames(garfield))]
##  [1] "index"     "X8AM"      "X9AM"      "X10AM"     "X11AM"     "X1PM"     
##  [7] "X2PM"      "X3PM"      "X4PM"      "X5PM"      "New.Field"
  garfielddb_table2<-garfielddb_table
  garfielddb_table2$index<-NULL
  garfielddb_table2$New.Field<-NULL
  
  
 
 #highlight data points that are different
  gf3<-garfielddb_table2==garfield
  gf3  
##       X8AM  X9AM X10AM X11AM Noon  X1PM  X2PM  X3PM X4PM  X5PM Commute
##  [1,] TRUE FALSE  TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [2,] TRUE FALSE FALSE FALSE TRUE  TRUE  TRUE FALSE TRUE  TRUE    TRUE
##  [3,] TRUE  TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [4,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [5,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [6,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [7,] TRUE  TRUE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
##  [8,] TRUE  TRUE  TRUE FALSE TRUE FALSE FALSE FALSE TRUE  TRUE    TRUE
##  [9,] TRUE FALSE  TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [10,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [11,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [12,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [13,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [14,] TRUE FALSE  TRUE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [15,] TRUE  TRUE FALSE FALSE TRUE FALSE FALSE  TRUE TRUE FALSE    TRUE
## [16,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [17,] TRUE FALSE FALSE  TRUE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [18,] TRUE FALSE FALSE FALSE TRUE FALSE  TRUE FALSE TRUE FALSE    TRUE
## [19,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [20,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE    TRUE
## [21,] TRUE FALSE FALSE FALSE TRUE FALSE FALSE  TRUE TRUE FALSE    TRUE
##       DayOfWeek WatchTV
##  [1,]      TRUE    TRUE
##  [2,]      TRUE    TRUE
##  [3,]      TRUE    TRUE
##  [4,]      TRUE    TRUE
##  [5,]      TRUE    TRUE
##  [6,]      TRUE    TRUE
##  [7,]      TRUE    TRUE
##  [8,]      TRUE    TRUE
##  [9,]      TRUE    TRUE
## [10,]      TRUE    TRUE
## [11,]      TRUE    TRUE
## [12,]      TRUE    TRUE
## [13,]      TRUE    TRUE
## [14,]      TRUE    TRUE
## [15,]      TRUE    TRUE
## [16,]      TRUE    TRUE
## [17,]      TRUE    TRUE
## [18,]      TRUE    TRUE
## [19,]      TRUE    TRUE
## [20,]      TRUE      NA
## [21,]      TRUE      NA

Problem 3

Generate both a static plot and an interactive plot with Plotly. The Plotly plot will only be visible in the HTML file (it will have to be downloaded from GIT). A four week forecast is presented at the end.

iata_demand<-read.csv("iata_demand_heatmap.csv",stringsAsFactors = FALSE,header=TRUE)

#Heat map colors are defined.  I take the visual aspects of data science very seriously.  This pallete comes from a Wall Street Journal visualization.  
cols<- c("#e7f0fa", #lighter than light blue
         "#c9e2f6", #light blue
         "#95cbee", #blue
         "#0099dc", #darker blue
         "#4ab04a", #green
         "#ffd73e", #yellow
         "#eec73a", #mustard
         "#e29421", #dark khaki (?)
         "#f05336", #orange red
         "#ce472e") #red

#I'm a huge fan of ggplot

library(ggplot2)
library(scales)
col1 = "#d8e1cf" 
col2 = "#438484"
library("viridis")
library("plotly")

library("forecast")

  url <- "https://raw.githubusercontent.com/jpatokal/openflights/master/data/airports.dat"
  
  #There is missing data in this file.  I would always address this in my professional work.  I'm reading it in to add data for the interactive heat map.
  airports <- read.delim(url, sep = ",", header = FALSE ,
                         col.names = c("Airport_ID", "Name", "City",
                                       "Country","IATA_FAA", "ICAO",
                                       "Latitude", "Longitude","Altitude",
                                       "Timezone", "DST", "TZ", "V13", "V14")
  ) %>% select(-V13, -V14) %>%
    ## add a column for the customized label to be displayed on the map
    mutate(Label = paste(paste0("<b>Airport</b>: ",
                                Name, " (", IATA_FAA, ")"),
                         paste0("<b>City</b>: ", City),
                         paste0("<b>Country</b>: ", Country),
                         sep = "<br/>"))
  
  airports2<-merge(x=iata_demand,y=airports,by.x="IATA",by.y="IATA_FAA",all.x=TRUE)
  airports2$label=NULL
  
    airports3<-airports2
  
  airports3<-airports3 %>%
    mutate(text = paste0("City: ", City, "\n","Country: ", Country))
  
  airports3$start<-as.Date(airports3$start)
  
  #First a create a ggplot object
   gg<-ggplot(airports3, aes(x=start, y=IATA,fill=PNRs,label=Name,text=text ) )  +  

    geom_tile(colour="white", 
           # width=0.9, height=0.9) + theme_minimal() +
           size=0.1,)+
 theme_minimal() +
    scale_fill_gradientn(colours=cols, limits=c(0, 20000),
                         
                         breaks=c(0, 3000,5000,10000,15000,20000), 
                         na.value=rgb(246, 246, 246, max=255),
                         labels=c("0k", "3k", "5k", "10k", "15k","20k"),
                         guide=guide_colourbar(ticks=T, nbin=50,
                                               barheight=.5, label=T, 
                                               barwidth=10)) +
    scale_x_date(breaks=date_breaks("1 months"),
                  labels=date_format("%b %y"))+
    theme(
         legend.position=c(.5, -0.1),
          #legend.position=c(.5, -.13),
          legend.direction="horizontal",
  legend.text=element_text(colour="grey20"),
  #plot.margin=grid::unit(c(1.5,1.5,1.5,1.5), "cm"),)
  plot.margin=grid::unit(c(.5,.5,1.5,.5), "cm"),)
   
   gg

   #Plotly is used to generate an interactive plot
     gg2<-ggplotly(gg,              text = ~n,
                textposition = "auto",
                hoverinfo = "text",
)
    
  gg2
    library(tidyverse)
    iata_demand$start<-as.Date(iata_demand$start)
  
#Lapply is used with arima to generate 4 week forecasts at the airport level
  iata_demand2<-iata_demand
  iata_demand2_wide = iata_demand2 %>% 
       spread(IATA, PNRs)
  
  lapply(iata_demand2_wide[,2:50], function(x) forecast(auto.arima(x),h=4))
## $AMS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1840.541 1271.457 2409.626 970.2020 2710.881
## 55       2137.936 1251.441 3024.432 782.1580 3493.715
## 56       2193.845 1181.595 3206.094 645.7428 3741.947
## 57       2217.366 1184.452 3250.279 637.6611 3797.070
## 
## $ATL
##    Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## 54       5536.925 3830.9039 7242.947  2927.7907 8146.060
## 55       3069.217 1309.9959 4828.438   378.7206 5759.713
## 56       1171.011 -588.2283 2930.250 -1519.5134 3861.536
## 57       2569.165  806.4165 4331.914  -126.7264 5265.057
## 
## $AUS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       2851.532 1878.062 3825.002 1362.738 4340.326
## 55       2782.432 1743.919 3820.945 1194.163 4370.701
## 56       2782.432 1743.919 3820.945 1194.163 4370.701
## 57       2782.432 1743.919 3820.945 1194.163 4370.701
## 
## $BNA
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       2188.134 1516.702 2859.566 1161.268 3215.001
## 55       2169.108 1417.413 2920.803 1019.489 3318.726
## 56       2169.108 1417.413 2920.803 1019.489 3318.726
## 57       2169.108 1417.413 2920.803 1019.489 3318.726
## 
## $BOS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       5943.889 3956.449 7931.329 2904.362 8983.417
## 55       6028.579 3858.102 8199.055 2709.122 9348.036
## 56       6028.579 3858.102 8199.055 2709.122 9348.036
## 57       6028.579 3858.102 8199.055 2709.122 9348.036
## 
## $CHI
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       8347.333 5408.792 11285.87 3853.223 12841.44
## 55       8865.793 5614.598 12116.99 3893.519 13838.07
## 56       8865.793 5614.598 12116.99 3893.519 13838.07
## 57       8865.793 5614.598 12116.99 3893.519 13838.07
## 
## $CLE
##    Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## 54      1311.3515  834.6589 1788.044  582.31301 2040.390
## 55       724.1266  220.7867 1227.466  -45.66529 1493.918
## 56       298.8987 -205.2687  803.066 -472.15873 1069.956
## 57       628.7117  123.6084 1133.815 -143.77710 1401.200
## 
## $CLT
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       3571.121 2417.168 4725.075 1806.302 5335.941
## 55       3491.538 2280.389 4702.687 1639.246 5343.830
## 56       3491.538 2280.389 4702.687 1639.246 5343.830
## 57       3491.538 2280.389 4702.687 1639.246 5343.830
## 
## $CMH
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1665.959 1126.323 2205.596 840.6567 2491.262
## 55       1695.571 1123.979 2267.163 821.3969 2569.746
## 56       1695.571 1123.979 2267.163 821.3969 2569.746
## 57       1695.571 1123.979 2267.163 821.3969 2569.746
## 
## $CPH
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1721.074 1182.569 2259.580 897.5015 2544.647
## 55       1928.909 1192.803 2665.015 803.1326 3054.686
## 56       1902.265 1115.453 2689.077 698.9394 3105.590
## 57       1804.172 1013.091 2595.254 594.3181 3014.027
## 
## $DEN
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       3128.209 2073.424 4182.993 1515.055 4741.362
## 55       3141.849 2029.663 4254.035 1440.907 4842.791
## 56       3141.849 2029.663 4254.035 1440.907 4842.791
## 57       3141.849 2029.663 4254.035 1440.907 4842.791
## 
## $DFW
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       7344.180 5029.293 9659.067 3803.866 10884.49
## 55       7297.262 4811.142 9783.382 3495.069 11099.45
## 56       7297.262 4811.142 9783.382 3495.069 11099.45
## 57       7297.262 4811.142 9783.382 3495.069 11099.45
## 
## $DTW
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       3099.616 2051.323 4147.910 1496.389 4702.843
## 55       3217.818 2086.089 4349.546 1486.989 4948.647
## 56       3217.818 2086.089 4349.546 1486.989 4948.647
## 57       3217.818 2086.089 4349.546 1486.989 4948.647
## 
## $EWR
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       6123.588 4142.283 8104.892 3093.444 9153.731
## 55       5958.662 3850.575 8066.749 2734.622 9182.702
## 56       5958.662 3850.575 8066.749 2734.622 9182.702
## 57       5958.662 3850.575 8066.749 2734.622 9182.702
## 
## $FRA
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1797.759 1137.122 2458.396 787.4022 2808.116
## 55       2183.005 1253.903 3112.107 762.0658 3603.945
## 56       2315.953 1353.047 3278.859 843.3155 3788.590
## 57       2315.953 1353.047 3278.859 843.3155 3788.590
## 
## $HOU
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       4755.157 3223.754 6286.561 2413.078 7097.236
## 55       4648.264 3007.924 6288.605 2139.581 7156.948
## 56       4648.264 3007.924 6288.605 2139.581 7156.948
## 57       4648.264 3007.924 6288.605 2139.581 7156.948
## 
## $IND
##    Point Forecast      Lo 80     Hi 80     Lo 95    Hi 95
## 54      1508.7199  973.62181 2043.8180  690.3580 2327.082
## 55       684.6650   98.49168 1270.8383 -211.8097 1581.140
## 56       388.8965 -201.05600  978.8489 -513.3580 1291.151
## 57      1013.5021  419.46191 1607.5423  104.9960 1922.008
## 
## $LAS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1806.075 778.2685 2833.882 234.1803 3377.971
## 55       1806.075 778.2685 2833.882 234.1803 3377.971
## 56       1806.075 778.2685 2833.882 234.1803 3377.971
## 57       1806.075 778.2685 2833.882 234.1803 3377.971
## 
## $LAX
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       3381.527 2278.603 4484.450 1694.751 5068.302
## 55       3521.629 2336.000 4707.258 1708.366 5334.892
## 56       3521.629 2336.000 4707.258 1708.366 5334.892
## 57       3521.629 2336.000 4707.258 1708.366 5334.892
## 
## $LON
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       9788.988 6874.383 12703.59 5331.484 14246.49
## 55      10123.114 6174.808 14071.42 4084.702 16161.53
## 56      10239.405 6183.732 14295.08 4036.788 16442.02
## 57      10279.880 6211.393 14348.37 4057.666 16502.09
## 
## $MAD
##    Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## 54           1275  279.1771 2270.823  -247.9797 2797.980
## 55           1275 -133.3062 2683.306  -878.8185 3428.819
## 56           1275 -449.8158 2999.816 -1362.8782 3912.878
## 57           1275 -716.6458 3266.646 -1770.9594 4320.959
## 
## $MCO
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1836.924 759.5193 2914.328 189.1759 3484.671
## 55       1961.400 832.5122 3090.289 234.9149 3687.886
## 56       2000.339 866.5382 3134.139 266.3404 3734.337
## 57       2012.519 878.2391 3146.799 277.7875 3747.251
## 
## $MEX
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1948.595 1356.789 2540.401 1043.506 2853.685
## 55       2300.218 1584.302 3016.134 1205.319 3395.117
## 56       2227.601 1458.933 2996.268 1052.025 3403.176
## 57       2261.099 1481.667 3040.532 1069.060 3453.139
## 
## $MIA
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54        1138.47 511.6385 1765.301 179.81411 2097.125
## 55        1138.47 483.1993 1793.740 136.32011 2140.619
## 56        1138.47 455.9441 1820.995  94.63682 2182.303
## 57        1138.47 429.7362 1847.203  54.55534 2222.384
## 
## $MIL
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1452.183 786.8099 2117.556 434.5827 2469.783
## 55       1795.026 884.8976 2705.153 403.1049 3186.946
## 56       1930.175 943.6649 2916.685 421.4381 3438.911
## 57       1953.807 952.8301 2954.784 422.9449 3484.669
## 
## $MSP
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       3043.512 2017.254 4069.771 1473.985 4613.039
## 55       3105.463 2004.919 4206.006 1422.327 4788.599
## 56       3105.463 2004.919 4206.006 1422.327 4788.599
## 57       3105.463 2004.919 4206.006 1422.327 4788.599
## 
## $MUC
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54       2305.363 1433.721 3177.006  972.3021 3638.425
## 55       2888.520 1727.863 4049.176 1113.4480 4663.591
## 56       3016.230 1797.204 4235.255 1151.8912 4880.568
## 57       2927.029 1706.382 4147.675 1060.2108 4793.846
## 
## $NYC
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       11500.15 7341.566 15658.73 5140.146 17860.15
## 55       12033.76 7628.732 16438.80 5296.849 18770.68
## 56       12033.76 7628.732 16438.80 5296.849 18770.68
## 57       12033.76 7628.732 16438.80 5296.849 18770.68
## 
## $PAR
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       8845.534 5623.038 12068.03 3917.152 13773.92
## 55       9552.843 5238.764 13866.92 2955.028 16150.66
## 56       9299.546 4716.563 13882.53 2290.478 16308.61
## 57       8853.250 4245.078 13461.42 1805.659 15900.84
## 
## $PDX
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1809.167 1125.790 2492.543 764.0324 2854.301
## 55       1956.382 1234.617 2678.147 852.5383 3060.226
## 56       2006.415 1280.347 2732.483 895.9897 3116.840
## 57       2023.419 1296.856 2749.982 912.2361 3134.602
## 
## $PEK
##    Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## 54           2201 1552.7270 2849.273 1209.5519 3192.448
## 55           2201 1284.2035 3117.797  798.8807 3603.119
## 56           2201 1078.1582 3323.842  483.7616 3918.238
## 57           2201  904.4539 3497.546  218.1039 4183.896
## 
## $PHL
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       4090.242 2822.846 5357.638 2151.927 6028.557
## 55       4081.019 2702.126 5459.912 1972.184 6189.854
## 56       4081.019 2702.126 5459.912 1972.184 6189.854
## 57       4081.019 2702.126 5459.912 1972.184 6189.854
## 
## $PHX
##    Point Forecast     Lo 80    Hi 80       Lo 95    Hi 95
## 54      1455.6522  454.5174 2456.787   -75.45129 2986.756
## 55       540.7059 -471.2870 1552.699 -1007.00372 2088.416
## 56       612.5448 -399.4045 1624.494  -935.09806 2160.188
## 57       612.5448 -596.7333 1821.823 -1236.88642 2461.976
## 
## $PIT
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1861.615 1270.865 2452.365 958.1414 2765.088
## 55       1860.188 1239.077 2481.300 910.2801 2810.097
## 56       1860.188 1239.077 2481.300 910.2801 2810.097
## 57       1860.188 1239.077 2481.300 910.2801 2810.097
## 
## $RDU
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       2305.603 1568.192 3043.015 1177.830 3433.377
## 55       2248.417 1452.871 3043.963 1031.734 3465.099
## 56       2248.417 1452.871 3043.963 1031.734 3465.099
## 57       2248.417 1452.871 3043.963 1031.734 3465.099
## 
## $SAN
##    Point Forecast    Lo 80    Hi 80    Lo 95   Hi 95
## 54       2032.925 1105.754 2960.095 614.9393 3450.91
## 55       2032.925 1105.754 2960.095 614.9393 3450.91
## 56       2032.925 1105.754 2960.095 614.9393 3450.91
## 57       2032.925 1105.754 2960.095 614.9393 3450.91
## 
## $SAT
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54       2240.216 1520.168 2960.263 1138.9979 3341.433
## 55       2119.037 1347.156 2890.918  938.5472 3299.527
## 56       2119.037 1347.156 2890.918  938.5472 3299.527
## 57       2119.037 1347.156 2890.918  938.5472 3299.527
## 
## $SEA
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       4242.851 2738.267 5747.435 1941.788 6543.914
## 55       4336.988 2731.175 5942.801 1881.109 6792.867
## 56       4336.988 2731.175 5942.801 1881.109 6792.867
## 57       4336.988 2731.175 5942.801 1881.109 6792.867
## 
## $SFO
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54       2795.655 867.3161 4723.995 -153.4851 5744.796
## 55       2795.655 790.0130 4801.298 -271.7099 5863.021
## 56       2795.655 715.5809 4875.730 -385.5440 5976.855
## 57       2795.655 643.7217 4947.589 -495.4432 6086.754
## 
## $SHA
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54       4615.619 3659.290 5571.947 3153.0403 6078.197
## 55       4040.970 2898.668 5183.272 2293.9702 5787.970
## 56       2898.563 1750.081 4047.045 1142.1116 4655.014
## 57       2469.000 1245.423 3692.578  597.6995 4340.301
## 
## $SIN
##    Point Forecast     Lo 80    Hi 80    Lo 95    Hi 95
## 54       1492.880  872.7351 2113.025 544.4501 2441.310
## 55       1636.495  932.8502 2340.139 560.3633 2712.626
## 56       1713.488  987.6196 2439.357 603.3679 2823.609
## 57       1754.766 1022.6343 2486.898 635.0672 2874.465
## 
## $SJC
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       4017.225 2513.501 5520.948 1717.478 6316.971
## 55       4157.803 2536.428 5779.179 1678.124 6637.483
## 56       4157.803 2536.428 5779.179 1678.124 6637.483
## 57       4157.803 2536.428 5779.179 1678.124 6637.483
## 
## $SNA
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1253.924 558.9334 1948.914 191.0278 2316.820
## 55       1253.924 540.3589 1967.489 162.6204 2345.227
## 56       1253.924 522.2557 1985.592 134.9340 2372.914
## 57       1253.924 504.5898 2003.258 107.9163 2399.931
## 
## $STL
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       2071.019 1443.434 2698.604 1111.211 3030.827
## 55       2059.155 1373.155 2745.156 1010.008 3108.303
## 56       2059.155 1373.155 2745.156 1010.008 3108.303
## 57       2059.155 1373.155 2745.156 1010.008 3108.303
## 
## $STO
##    Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## 54       1910.799 1354.0211 2467.578 1059.2804 2762.318
## 55       2158.393 1400.4871 2916.300  999.2758 3317.511
## 56       1735.367  834.5531 2636.181  357.6911 3113.043
## 57       1735.367  834.5531 2636.181  357.6911 3113.043
## 
## $SYD
##    Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## 54       939.5898 300.6534 1578.526 -37.57912 1916.759
## 55      1216.9576 441.0604 1992.855  30.32518 2403.590
## 56      1408.0525 574.9886 2241.116 133.99131 2682.114
## 57      1539.7089 680.8409 2398.577 226.18358 2853.234
## 
## $TLS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1432.836 749.5631 2116.108 387.8605 2477.811
## 55       1648.496 765.6362 2531.355 298.2786 2998.713
## 56       1703.546 772.1798 2634.911 279.1446 3127.946
## 57       1697.829 759.8561 2635.803 263.3230 3132.336
## 
## $WAS
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       5855.704 3912.386 7799.023 2883.655 8827.754
## 55       5849.667 3727.666 7971.668 2604.347 9094.987
## 56       5849.667 3727.666 7971.668 2604.347 9094.987
## 57       5849.667 3727.666 7971.668 2604.347 9094.987
## 
## $YUL
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 54       1195.993 691.7252 1700.261 424.7818 1967.205
## 55       1388.481 803.3301 1973.632 493.5698 2283.393
## 56       1501.791 891.1067 2112.476 567.8297 2435.753
## 57       1568.493 949.2055 2187.780 621.3747 2515.610

Problem #5

I am assuming that the digit at each specific position, can be in the set (0,1,2,3,4,5,6,7,8,9). There are positional constraints for an actual clock but these will not be addressed here.

The number has the format _ _ _ _ _ _

I will refer to each _ as a position

[Position 1, Position 2, Position 3, Position 4, Position 5, Position 6]

With the horizontal and vertical rotations, for the six-digit number to be the same both before and after the rotations, all individual positions will contain the same digit before and after the rotations. For n=1 to 3, Position n will move to Position n+3, and vice versa. For the six digit number to be the same both before and after the rotations, the resulting digit after the rotations in each position in n=1:3, must correspond to the same digit in the n+3 corresponding position, before the rotation, and vice versa. Thus, there are symmetry implications.

Each individual digit must have a combination of a certain vertical and horizontal symmetry that results in the same number after the two rotations. Thus, each digit must be in the set (0,1,2,5,6,8,9). For digits in the set (0,1,2,5,8), each digit in positions n=1:3 must map to the same number in the n+3 position. For numbers in the set (6,9), at positions n=1:3; 6 must map to 9 in the corresponding n+3 position, and 9 must map to 6. Thus, at positions 1 to 3, there are 7 digit choices at each position. Since, positions 1 to 3 set the assignments at positions 4 to 6, there are seven-digit options for position in n=1:3. Thus there are 7^3 total numbers that will be the same before and after the rotations. In total, there are a total of 10^6 different numbers. Thus, the probability of randomly drawing a number that meets our criteria is precisely 343/10^6.